///////////////////////////
// association/Execution //
///////////////////////////
$(document).ready(function() {
	$('#recherche').bind('keyup', autocompletion);
	$('#formRecherche').bind('submit', verifForm);
	$('#recherche').autocomplete="off";
});

// /////////////////////////
// fonctions JavaScript //
// /////////////////////////
var verifForm = function() {
	if($('#recherche').val()==""){
		return false;
	}
	else
		return true;
}

var autocompletion = function() {
	var deb = $(this).val();
	if (deb == "") {
		$('#suggestions').hide();
	} else {
		$.post("autocompletionMat.php", {
			debut : ""+deb+""
		}, function(data) {
			if(data) {
				$('#suggestions').show();
				$('#autoSuggestionsList .mat').remove();
				$('#autoSuggestionsList').append(data);
				$('#autoSuggestionsList li').bind('click', fill);
			}
			else {
				$('#autoSuggestionsList .mat').remove();
// $('#suggestions').hide();
			}
		});
	}

}

function fill() {
	$('#recherche').val($(this).text());
	setTimeout("$('#suggestions').hide();", 200);
}